package com.jsmile.cloud.msgcenter.zf.strategy.notify;

import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.jsmile.cloud.msgcenter.zf.enums.AliNotifyTypeEnum;
import com.jsmile.cloud.msgcenter.zf.req.ali.AliServiceMarketOrderNotifyResponse;
import com.jsmile.cloud.msgcenter.zf.strategy.interfaces.IAlilNotify;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
@EnableAsync
public class ServiceMarketOrderNotifyStrategy implements IAlilNotify {

    @Override
    public String getNotifyType() {
        return AliNotifyTypeEnum.SERVICEMARKET_ORDER_NOTIFY.getType();
    }

    /**
     * 订购回调
     *
     * @param data
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String excute(String data) {
        log.info("订购回调参数：{}", data);
        data = data.replace("\\", "").replace("\"{", "{").replace("}\"", "}");
        log.info("转字符串授权回调参数：{}", data);
        // 解析回调消息请求参数
        AliServiceMarketOrderNotifyResponse notifyResponse = JSON.parseObject(data, AliServiceMarketOrderNotifyResponse.class);
        return SUCCESS;
    }
}
